package com.weigee.ktv.view.widget

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.CompoundButton
import com.weigee.ktv.R
import kotlinx.android.synthetic.main.item_paying_type.view.*
import skin.support.widget.SkinCompatFrameLayout

/**
 * Created by linde on 2017/6/14.
 * LinDe
 */
class PayingItemView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : SkinCompatFrameLayout(context, attrs, defStyleAttr) {
    var isChecked: Boolean = false
        set(value) {
            field = value
            cb_paying_type?.isChecked = value
        }
    var onCheckChangeListener: CompoundButton.OnCheckedChangeListener? = null
        set(value) {
            field = value
            cb_paying_type?.setOnCheckedChangeListener(value)
        }
    var isCanToRecharge = false
        set(value) {
            field = value
            tv_paying_type_recharge?.visibility = if (value) View.VISIBLE else View.GONE
        }
    var msg = "钱包支付"
        set(value) {
            field = value
            tv_payting_type_msg?.text = value
        }
    var logo = 0
        set(value) {
            field = value
            civ_paying_type_logo?.setImageResource(value)
        }

    init {
        LayoutInflater.from(context).inflate(R.layout.item_paying_type, this, true)

        attrs?.let {
            val typeArray = context.obtainStyledAttributes(it, R.styleable.PayingItemView)

            logo = typeArray.getResourceId(R.styleable.PayingItemView_paying_type_logo, logo)
            msg = typeArray.getString(R.styleable.PayingItemView_paying_type_msg)
            isCanToRecharge = typeArray.getBoolean(R.styleable.PayingItemView_paying_type_recharge, isCanToRecharge)
            isChecked = typeArray.getBoolean(R.styleable.PayingItemView_paying_type_checked, isChecked)

            typeArray.recycle()
        }
    }
}